package com.hcy.controller;

import com.hcy.ordermodel.dto.request.PayOrderRequestDTO;
import com.hcy.rabbitbasicmodel.enums.Code;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.rabbitbasicmodel.model.ReturnResult;
import com.hcy.userclient.client.UserInfoClient;
import com.hcy.usermodel.dto.request.CustomerInfoRequestDTO;
import com.hcy.usermodel.dto.response.CustomerInfoResponseDTO;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author huchenying
 * @Description 
 * @Date  2021/12/20 18:40
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserInfoClient userInfoClient;

    /**
     * @Author huchenying
     * @Description 获取基本信息
     * @Date  2021/12/20 12:46
     **/
    @PostMapping("/baseInfo")
    public ReturnResult baseInfo(@RequestBody PayOrderRequestDTO requestDTO){
        logger.info("baseInfo request param -> {}",requestDTO);
        if(StringUtils.isEmpty(requestDTO.getCustomerId())){
            return ReturnResult.fail("参数校验错误！");
        }
        CustomerInfoRequestDTO customerInfoRequestDTO = new CustomerInfoRequestDTO();
        customerInfoRequestDTO.setPhone(requestDTO.getCustomerId());
        try {
            ResponseData<CustomerInfoResponseDTO> responseData = userInfoClient.baseInfo(customerInfoRequestDTO);
            if(responseData.getCode() != Code.Success){
                return ReturnResult.fail("查询用户失败！");
            }
            logger.info("res -> {}",ToStringBuilder.reflectionToString(responseData.getData()));
            return ReturnResult.success().setData(responseData.getData());
        } catch (Exception e) {
           logger.error("e -> {}", ToStringBuilder.reflectionToString(e));
           return ReturnResult.fail("查询用户失败！");
        }
    }
}
